package com.didi.gulimall.product.web;

import com.didi.gulimall.product.entity.CategoryEntity;
import com.didi.gulimall.product.service.CategoryService;
import com.didi.gulimall.product.vo.Catelog2Vo;
import com.didi.gulimall.product.vo.CatelogVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author 10626
 */
@Controller
@Slf4j
public class HomeController {
    @Autowired
    private CategoryService categoryService;

//    @GetMapping({"/", "index.xml"})
    public String home(Model model) {
        List<CategoryEntity> categoryEntities = categoryService.getLevelCategoryOne();
        model.addAttribute("categorys", categoryEntities);
        return "index";
    }

    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<Catelog2Vo>> getCatalogJson() {
        return categoryService.getCatalogJson2();
    }

    @ResponseBody
    @GetMapping("/majorization/catalog.json")
    public Map<String, List<CatelogVo>> majorizationGetCatalogJson() {
        return categoryService.majorizationGetCatalogJson();
    }

    @ResponseBody
    @GetMapping("/hello")
    public String hello() {
        return "hello";
    }
}
